package com.demo.Main.FtpUtil;

import org.apache.commons.net.ftp.FTP;
import org.apache.commons.net.ftp.FTPClient;

import java.io.*;

/**
 * @author zxc
 *
 * 此方法测试成功
 *
 */

public class TestDemo{
    public static void main(String[] args) {

        String hostname = "8.130.77.94";
        int port = 21;
        String username = "zxc1213866";
        String password = "147258369";
        String workingPath = "/www/wwwroot/zxc1213866";
        String str = "E:\\Note\\project\\file-synchronization-server\\localfile\\server.txt";
        /*
        String upload = MyFtpUtil.upload("", "cat.png",str, hostname, port, username, password, null);
        System.out.println(upload);*/
        File file = new File(str);
        //System.out.println(file.exists());
        FTPClient ftpClient = new FTPClient();
        try (FileInputStream fis = new FileInputStream(file);){

            ftpClient.connect(hostname,port);
            ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
            ftpClient.login(username, password);
            ftpClient.enterLocalPassiveMode();
            //boolean b1 = ftpClient.changeWorkingDirectory("");
            //System.out.println(b1);

            boolean b = ftpClient.storeFile("server.txt", fis);
            System.out.println(b);
            fis.close();
            //System.out.println("上传成功");

        } catch (IOException e) {
            System.out.println("上传失败");
            throw new RuntimeException(e);
        }


    }

}
